CREATE TABLE IF NOT EXISTS `users` (
  `name` varchar(128) DEFAULT '',
  `email` varchar(128) DEFAULT '',
  `id` int(12) NOT NULL DEFAULT '0',
  `ip` varchar(15) DEFAULT '',
  `vscode` varchar(512) DEFAULT '',
  `vscode_display` varchar(512) DEFAULT '',
  `gitlab` varchar(512) DEFAULT '',
  `hub` varchar(512) DEFAULT '',
  `controller` varchar(512) DEFAULT '',
  `username` varchar(128) DEFAULT '',
  `password` varchar(128) DEFAULT '',
  `grade` varchar(6) DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


{% for number in range(1, student_total|int + 1) %}
  {% for host in groups['control_nodes'] %}
    {% if hostvars[host].student is defined and "student" + number | string == hostvars[host].student %}
      {% if hostvars[host].student is defined and "student" + number | string == hostvars[host].student %}
      INSERT INTO `users` (`id`, `ip`, `vscode`, `vscode_display`, `gitlab`, `hub`, `controller`, `username`, `password`) VALUES ({{ number }},'{{ hostvars[host].ansible_host }}',
      {% if workshop_type == "windows" %}
        'https://student{{ number }}.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}:{{ code_server_port }}/?folder=vscode-remote%3A%2F%2Fstudent{{ number }}-code.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}%2Fhome%2Fstudent%2Fwindows-workshop%2Fworkshop_project',
      {% else %}
        'https://student{{ number }}.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}:{{ code_server_port }}',
      {% endif %}
        'https://student{{ number }}.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}:{{ code_server_port }}',
      {% if workshop_type == "windows" or workshop_type == "configascode" %}
        'https://gitlab.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}',
      {% else %}
        '',
      {% endif %}
      {% if automation_hub is defined and automation_hub|bool %}
        {% if dns_type != 'none' %}
          'https://hub-student.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}',
        {% else %}
          'https://{{ hostvars["automation-hub-host"].ansible_host }}',
        {% endif %}
      {% else %}
        '',
      {% endif %}
      {% if controllerinstall is defined and controllerinstall %}
        {% if dns_type != 'none' %}
          'https://student{{ number }}.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}',
        {% else %}
          'https://{{ hostvars[host].ansible_host }}',
        {% endif %}
      {% else %}
        '',
      {% endif %}
        'student{{ number }}', '{{ admin_password }}')
        ON DUPLICATE KEY UPDATE `password` = '{{ admin_password }}';
      {% endif %}
    {% endif %}
  {% endfor %}
{% endfor %}
